package com.Renting.controller;

import com.Renting.domain.Renting;
import com.Renting.service.ServiceGain;
import com.Renting.service.ServiceRenting;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class RentingController {

    @Resource
    ServiceRenting serviceRenting;
    @Resource
    ServiceGain serviceGain;


    //预约程序
    @PostMapping(value = "/RentingSubscribe.do",produces = "text/html; charset=utf-8")
    @ResponseBody
    public String RentingSubscribe(Renting renting,HttpSession session){
       boolean result= serviceRenting.ServiceRentingSubscription(renting,session);
       if(result){
           return "预约成功!请尽快缴费入住";
       }else{
           return "预约失败!该房间已被预定";
       }

    }

    //查看指定的房间类型
    @GetMapping(value = "/RentingInquire.do", produces = "text/html; charset=utf-8")
    public String RentingInquire(Renting renting, HttpSession session){
        serviceGain.ServiceRentingInquire(renting,session);
        return "shop-single";
    }

    //查看自己预约的房间
    @GetMapping(value = "/MyRenting.do", produces = "text/html; charset=utf-8")
    public String MyRenting(HttpSession session){
        serviceGain.MyRentingService(session);
        return "shop-My";
    }

    //支付入住
    @GetMapping(value = "/RentingPay.do",produces = "text/html; charset=utf-8")
    public String RentingPay(Renting renting,HttpSession session){

        if(serviceRenting.ServiceRentingRoom(renting)){
            return "shop-My";
        }else{
            //支付成功
            serviceRenting.ServiceRentingPay(renting,session);
            serviceGain.MyRentingService(session);
            return "shop-My";
        }


    }

    //取消入住
    @GetMapping(value = "/RentingPayCancel.do",produces = "text/html; charset=utf-8")
    public String RentingPayCancel(Renting renting,HttpSession session){

        if(serviceRenting.ServiceRentingPayCancel(renting)){
            serviceGain.MyRentingService(session);
            return "shop-My";
        }else{
            return "shop-My";
        }
    }

    //查看自己入住的房间
    @GetMapping(value = "/MyRoom.do",produces = "text/html; charset=utf-8")
    public String MyRoom(HttpSession session){
        serviceGain.MyRoomService(session);
        return "shop-My-Room";
    }

    //退出并删除作用域内的数据
    @GetMapping(value = "/Quit.do",produces = "text/html; charset=utf-8")
    public String Quit(HttpSession session){
        session.removeAttribute("ListRenting");
        session.removeAttribute("ListRentingInquire");
        session.removeAttribute("ErrorLogin");
        session.removeAttribute("Message");
        session.removeAttribute("hint");
        return "Login";
    }


}